//
//  VideoListCell.m
//  cityStar
//
//  Created by joyban on 15-1-21.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "VideoListCell.h"
#import "UIColor+FlatUI.h"

@implementation VideoListCell

+(CGFloat)heightOfTableCell
{
    return 88;
}


- (void)awakeFromNib {
    // Initialization code
}

-(void)setDataVieo:(VideoArrayModel *)model
{
    NSString * imagePath = @"";
//    NSString *imagestring = [NSString stringWithFormat:@"%@",model.image];
//    if(![imagestring isEqualToString:@"0"])
//    {
        if (model.image.count>0) {
            imagePath = [NSString stringWithFormat:@"%@",model.image[0]];
            [self.heardimage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.icszx.com/image/c/id/%@/w/182/h/132/m/0",imagePath]] placeholderImage:[UIImage imageNamed:@"品牌列表_主图"]];
        }
//    }
    self.titleLabel.text = model.title;

    self.adresslabel.text = model.district_name;
    NSString *room = [NSString stringWithFormat:@"%@室",model.room];
    NSString *hall = [NSString stringWithFormat:@"%@厅",model.hall];
    NSString *bathroom = [NSString stringWithFormat:@"%@卫",model.bathroom];
    NSString *area = [NSString stringWithFormat:@"%@平方",model.area];
    self.numlabel.text = [NSString stringWithFormat:@"%@%@%@%@",room,hall,bathroom,area];
    NSInteger typestring = [[NSString stringWithFormat:@"%@",model.category] integerValue];
    
    switch (typestring) {
        case 1:{
            self.typelabel.text = @"整租";
            NSString *stringMoney = [NSString stringWithFormat:@"%@",model.money];
            self.pricelaebl.text = [NSString stringWithFormat:@"%@元/月",stringMoney];
        }
            break;
        case 2:{
            self.typelabel.text = @"合租";
            NSString *stringMoney2 = [NSString stringWithFormat:@"%@",model.money];
            self.pricelaebl.text = [NSString stringWithFormat:@"%@元/月",stringMoney2];
        }
            break;
        case 3:{
            self.typelabel.text = @"出售";
            NSString *stringMoney3 = [NSString stringWithFormat:@"%@",model.money];
            self.pricelaebl.text = [NSString stringWithFormat:@"%@元/平方",stringMoney3];
        }
            break;
        default:
            break;
    }
    
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[[NSString stringWithFormat:@"%@",model.modify_time] intValue]];

    NSLog(@"date1:%@",confromTimesp);
    self.timelabel.text = [self dateStringFromNow:confromTimesp];
    
    NSInteger sourcestr = [[NSString stringWithFormat:@"%@",model.source] integerValue];
    switch (sourcestr) {
        case 1:
            [self.titleImage setImage:[UIImage imageNamed:@"b"]];
            break;
        case 2:
            [self.titleImage setImage:[UIImage imageNamed:@"a"]];
            break;
        default:
            self.titleImage.hidden = YES;
            break;
    }
    
    NSString *status = [NSString stringWithFormat:@"%@",model.status];
    if([status isEqualToString:@"0"])
    {
        switch (sourcestr) {
            case 1:
                [self.titleImage setImage:[UIImage imageNamed:@"d"]];
                break;
            case 2:
                [self.titleImage setImage:[UIImage imageNamed:@"c"]];
                break;
            default:
                self.titleImage.hidden = YES;
                break;
        }
        self.titleLabel.textColor = [UIColor colorFromHexCode:@"949494"];
        NSString *name = [NSString stringWithFormat:@"%@%@",@"[已作废]",model.title];
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:name];
        [attri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 5)];
        [self.titleLabel setAttributedText:attri];
        self.pricelaebl.textColor = [UIColor colorFromHexCode:@"949494"];
        self.typelabel.backgroundColor = [UIColor colorFromHexCode:@"949494"];
    }else{
        self.titleLabel.text = model.title;
        self.timelabel.textColor = [UIColor colorFromHexCode:@"ff9b5f"];
        self.pricelaebl.textColor = [UIColor colorFromHexCode:@"ff9b5f"];
        self.typelabel.backgroundColor = [UIColor colorFromHexCode:@"ff7676"];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(NSString*)dateStringFromNow:(NSDate*)date{
    NSTimeInterval time = -[date timeIntervalSinceNow];
    if (time<0) {
        return @"";
    }else {
        if (time<3600*24) {
            if (time>=0.0 && time <60.0) {
                return @"刚刚";
            }else if (time>=60.0 && time <60.0*60.0) {
                return [NSString stringWithFormat:@"%d分钟前",(int)time/60];
            }else if (time>=3600.0 && time <3600.0*24) {
                return [NSString stringWithFormat:@"%d小时前",(int)time/3600];;
            }
        }else {
            
            NSCalendar* calendar = [NSCalendar currentCalendar];
            NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit|NSWeekCalendarUnit fromDate:date toDate:[NSDate date] options:0];
            if ([components year]>0) {
                int month = [components year]*12+[components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components month]>0){
                int month = [components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components week]>0){
                return [NSString stringWithFormat:@"%d周前",[components week]];
            }else if([components day]>0){
                return [NSString stringWithFormat:@"%d天前", [components day]];
            }
        }
    }
    return @"";
}

@end
